<template>
  <div class="gallery-list" @mouseenter="isHover = true" @mouseleave="isHover = false">
    <div class="gallery-container gallery-caption container-content" :style="{backgroundColor: modelValue?.bgColor}">
      <a-row class="caption-row">
        <a-col v-for="item in modelValue?.data" :key="item.id" :sm="{span: 24 / modelValue?.mobileCol}" :md="{span: 24 / modelValue?.desktopCol}">
          <div class="gallery-caption" :class="[item.url && 'has-url', item.profile && 'has-profile']" @click="handleClick(item)">
            <div class="gallery-caption__img">
              <img :src="item.imgSrc" :alt="item.alt">
            </div>
            <div class="gallery-caption__title tx-subtitle text-blue text-center mt-3 mt-md-4 px-3">{{ item.title }}</div>
            <div v-if="item.text" class="tx-body text-teal-darkest text-center mt-2 mt-md-3 mb-3">{{ item.text }}</div>
          </div>
        </a-col>
      </a-row>
    </div> 

    <Operate v-if="!isPreview" v-model:show="isHover" @handle-edit="showSetting = true" @handle-delete="handleDelete" @handle-copy="handleCopy" @handle-paste="handlePaste"></Operate>
  </div>

  <Setting v-if="!isPreview" v-model:show="showSetting" :data="modelValue"></Setting>
  <ProfileModel v-model:show="showProfile" :data="profileData"></ProfileModel>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { randomString } from '@/utils/common'
import Setting from './setting.vue'
import Operate from '@/common/Operate/index.vue'
import ProfileModel from '@/common/Profile/modal.vue'

// 定义组件名称
defineOptions({
  name: 'GalleryList'
})

const props = defineProps({
  modelValue: {
    type: Object,
    default: () => {}
  },

  // 是否预览
  isPreview: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['update:modelValue', 'handleDelete', 'handleCopy', 'handlePaste'])

const handleInit = () => {
  if (props.modelValue && props.modelValue.data) return // 有数据不用初始化
  const data = {
    id: props.modelValue?.id || randomString(),
    type: 'GalleryList',
    bgColor: '',
    desktopCol: 4,
    mobileCol: 2,
    data: [
      {
        id: randomString(),
        type: 'GalleryListItem',
        title: '耀华国际教育学校浙江桐乡',
        text: '123',
        imgSrc: 'https://osswebsite-test.cedim.cn/media-library/ywies-tx/images/high-school-test/home/different_1_optim.png',
        alt: '',
        url: 'https://www.baidu.com',
      },
      {
        id: randomString(),
        type: 'GalleryListProfile',
        title: '耀华国际教育学校浙江桐乡',
        text: '123',
        imgSrc: 'https://osswebsite-test.cedim.cn/media-library/ywies-tx/images/high-school-test/home/different_1_optim.png',
        alt: '',
        url: '',
        profile: {
          title: '耀华国际教育学校浙江桐乡',
          subTitle: '耀华国际教育学校浙江桐乡',
          name: '耀华国际教育学校浙江桐乡',
          label: '123',
          imgSrc: 'https://osswebsite.ycyw.com/media-library/ywies-bj/images/home/ywies-tx.jpg',
          alt: '',
          buttonList: {
            id: randomString(),
            type: 'BtnList',
            readOnly: true,
            width: '',
            bgColor: '',
            data: [
              {
                id: randomString(),
                type: 'white',
                text: '了解更多',
                url: 'https://www.baidu.com',
                isExternal: false
              },
              {
                id: randomString(),
                type: 'light',
                text: '了解更多',
                url: 'https://www.baidu.com',
                isExternal: false
              }
            ]
          },
          paragraphs: [{
            id: randomString(),
            title: '123',
            content: '123'
          }]
        }
      },
    ]
  }
  emit('update:modelValue', data)
} 

const isHover = ref<boolean>(false);
const showSetting = ref<boolean>(false);

const handleDelete = () => {
  emit('handleDelete', props.modelValue.id)
}

const handleCopy = () => {
  emit('handleCopy', props.modelValue)
}

const handlePaste = (type: string) => { 
  emit('handlePaste', type) 
}

const showProfile = ref<boolean>(false)
const profileData = ref<any>({})
const handleClick = (item: any) => {
 if (item.type !== 'GalleryListProfile') return 
  profileData.value = item.profile
  showProfile.value = true
}

handleInit()
</script>

<style lang="scss" scoped>
.gallery-list {
  position: relative;
  width: 100%;
}

.gallery-list .default-row {
  --bs-gutter-x: 12px;
  --bs-gutter-y: 12.79px;
}

.tx-subtitle {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: .1em
}

@media(max-width: 1023.98px) {
  .tx-subtitle {
      font-size:14px;
      line-height: 1.714
  }
}

@media(max-width: 767.98px) {
  .tx-subtitle {
      line-height:1.428
  }
}

.tx-body {
  font-size: 16px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

@media (max-width: 1023.98px) {
  .tx-body {
    font-size: 14px;
    line-height: 1.285;
    letter-spacing: 0.01em;
  }
}



.text-blue {
  --bs-text-opacity: 1;
  color: rgba(0,72,232,var(--bs-text-opacity))!important;
}

.text-center {
  text-align: center!important
}

.mt-2 {
  margin-top: 8px!important
}
.mt-3 {
  margin-top: 12px!important
}

.mt-md-3 {
  margin-top: 12px!important
}
.mt-md-4 {
  margin-top: 16px!important
}

.px-3 {
  padding-right: 12px!important;
  padding-left: 12px!important
}

.mb-3 {
  margin-bottom: 12px!important
}

.text-teal-darkest {
  --bs-text-opacity: 1;
  color: rgba(26,28,32,var(--bs-text-opacity))!important;
}

@media (max-width: 767.98px) {
  .gallery-list .default-row {
    --bs-gutter-x: 8px;
    --bs-gutter-y: 8.37px;
  }
}

.gallery-list .wide-row {
  --bs-gutter-y: 12.79px;
}

@media (max-width: 767.98px) {
  .gallery-list .wide-row {
    --bs-gutter-y: 8.37px;
  }
}

.gallery-list .caption-row {
  --bs-gutter-x: 16px;
  --bs-gutter-y: 24px;
}

.gallery-list .gallery-container.gallery-four-box,
.gallery-list .gallery-container.gallery-gallery {
  padding-left: 0;
  padding-right: 0;
  max-width: 1280px;
}

.gallery-list .gallery-container.gallery-gallery .gallery-row {
  --bs-gutter-x: 12px;
  --bs-gutter-y: 12px;
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container.gallery-gallery .gallery-row {
    --bs-gutter-x: 8px;
    --bs-gutter-y: 8px;
  }
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container.gallery-caption {
    padding-left: 0;
    padding-right: 0;
  }
}

@media (min-width: 1280px) {
  .gallery-list .gallery-container.gallery-caption-round {
    --max-width: clamp(952px, calc(76.27765vw - 24.35393px), 1440px);
  }
}

.gallery-list .gallery-container.gallery-caption-round .caption-row {
  --bs-gutter-x: 18px;
  --bs-gutter-y: 24px;
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container.gallery-caption-round .caption-row {
    --bs-gutter-x: 10px;
    --bs-gutter-y: 13.14px;
  }
}

@media (min-width: 1024px) {
  .gallery-list .gallery-container.gallery-circle {
    max-width: 1064px;
  }
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container.gallery-timeline,
  .gallery-list .gallery-container.gallery-timeline-col {
    padding-left: 0;
    padding-right: 0;
  }
}

.gallery-list .gallery-container.gallery-timeline-col .row {
  --bs-gutter-x: 48px;
  --bs-gutter-y: 24px;
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container.gallery-timeline-col .row {
    --bs-gutter-x: 24px;
  }
}

.gallery-list .gallery-container .gallery-row {
  --bs-gutter-x: 8px;
  --bs-gutter-y: 8px;
}

@media (max-width: 767.98px) {
  .gallery-list .gallery-container .gallery-row {
    --bs-gutter-x: 4px;
    --bs-gutter-y: 4px;
  }
}

.gallery-list .row-center {
  justify-content: center;
}

.gallery-caption {
  width: 100%;
  height: 100%;
}

.gallery-caption.has-profile {
  cursor: pointer;
}

.gallery-caption__img img {
  width: 100%;
  height: auto;
  -o-object-fit: contain;
  object-fit: contain;
  transition: transform .3s ease-in-out;
}

.gallery-caption__title {
  text-decoration: none;
  display: block;
}

.gallery-caption__img {
  display: block;
  overflow: hidden;
}

.gallery-caption .has-url .gallery-caption__img img {
  &:hover {
    transform: scale(1.05);
  }
}

.arco-row {
  --bs-gutter-x: 16px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
  margin-top: calc(var(--bs-gutter-y)*-1);
  margin-right: calc(var(--bs-gutter-x)*-0.5);
  margin-left: calc(var(--bs-gutter-x)*-0.5);
}

.arco-row > * {
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  padding-right: calc(var(--bs-gutter-x)*0.5);
  padding-left: calc(var(--bs-gutter-x)*0.5);
  margin-top: var(--bs-gutter-y);
}
</style>